/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package elaborate.h2x.transform;

import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Node;

/**
 * an XHTML node that is under transforming
 * identified by id
 * @author lendle
 */
public class TransformingNode {

    protected TransformingNodeId id;
    protected boolean includedInResult=false;
    protected TransformingNode parentNode;
    protected List<TransformingNode> childNodes=new ArrayList<TransformingNode>();
    //protected List<Def> defList=new ArrayList<Def>();
    protected Def def=null;
    protected List<Relation> relationList=new ArrayList<Relation>();
    //protected List<Root> rootList=new ArrayList<Root>();
    protected Root root=null;
    protected Node originalNode;
    protected AsRootSetting asRootSetting;

    /**
     * Get the value of asRootSetting
     *
     * @return the value of asRootSetting
     */
    public AsRootSetting getAsRootSetting() {
        return asRootSetting;
    }

    /**
     * Set the value of asRootSetting
     *
     * @param asRootSetting new value of asRootSetting
     */
    public void setAsRootSetting(AsRootSetting asRootSetting) {
        this.asRootSetting = asRootSetting;
    }


    /**
     * Get the value of childNodes
     *
     * @return the value of childNodes
     */
    public List<TransformingNode> getChildNodes() {
        return childNodes;
    }

    /**
     * Get the value of parentNode
     *
     * @return the value of parentNode
     */
    public TransformingNode getParentNode() {
        return parentNode;
    }

    /**
     * Set the value of parentNode
     *
     * @param parentNode new value of parentNode
     */
    public void setParentNode(TransformingNode parentNode) {
        this.parentNode = parentNode;
    }


    /**
     * Get the value of includedInResult
     * true if this node is included in the transformation result
     * @return the value of includedInResult
     */
    public boolean isIncludedInResult() {
        return includedInResult;
    }

    /**
     * Set the value of includedInResult
     *
     * @param includedInResult new value of includedInResult
     */
    public void setIncludedInResult(boolean includedInResult) {
        this.includedInResult = includedInResult;
    }


    /**
     * Get the value of id
     *
     * @return the value of id
     */
    public TransformingNodeId getId() {
        return id;
    }

    /**
     * Set the value of id
     *
     * @param id new value of id
     */
    public void setId(TransformingNodeId id) {
        this.id = id;
    }

    /**
     * Get the value of originalNode
     *
     * @return the value of originalNode
     */
    public Node getOriginalNode() {
        return originalNode;
    }

    /**
     * Set the value of originalNode
     *
     * @param originalNode new value of originalNode
     */
    public void setOriginalNode(Node originalNode) {
        this.originalNode = originalNode;
    }


    /**
     * Get the value of def
     *
     * @return the value of def
     */
    public Def getDef() {
        return def;
    }

    public List<Relation> getRelationList() {
        return relationList;
    }

    public Root getRoot() {
        return root;
    }

    public void setDef(Def def) {
        this.def = def;
    }

    public void setRoot(Root root) {
        this.root = root;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TransformingNode other = (TransformingNode) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        if(originalNode!=null){
            if(originalNode.getNodeType()==Node.TEXT_NODE){
                return originalNode.getNodeValue().trim();
            }
            else if(originalNode.getNodeType()==Node.ATTRIBUTE_NODE){
                return originalNode.getNodeName()+"="+originalNode.getNodeValue();
            }else{
                return originalNode.getNodeName();
            }
        }
        return "";
    }

}
